from concurrent.futures import ThreadPoolExecutor
from urllib.request import urlopen, Request
import os

def download_img(url: str):
    site_url = Request(url, headers={})

    with urlopen(site_url) as web_file:
        img_data = web_file.read()
        
    if not img_data:
        raise Exception(f"Error: can not load the image from {url}")
    
    file_name = os.path.basename(url)
    
    with open(file_name, "wb") as f:
        f.write(img_data)
        
    return "Download image successfully, {}".format(url)


urls = [
    "https://img0.bdstatic.com/static/searchresult/img/baseimg3_4f26a23.png",
    # "..."
]
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36",
    "content-type": "Content-Type: image/jpeg"
}
with ThreadPoolExecutor() as ececutor:
    results = ececutor.map(download_img, urls)
    for r in results:
        print(r)